package com.chhuang.ewcrm.utils;

import com.jfoenix.controls.JFXDialog;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.StackPane;

import java.util.Optional;

/**
 * @author chhuang
 * @create 2020-10-11-14:25
 */
public class MyAlert {
    private MyAlert(){}

    public static void showError(String title, String headText, String content) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle(title);
        alert.setHeaderText(headText);
        alert.setContentText(content);
        alert.getDialogPane().setStyle("fx-font-size: 14;");
        alert.showAndWait();
    }

    public static void showErrorLater(String title, String headText, String content){
        Platform.runLater(() -> showError(title, headText, content));
    }

    public static void showAlert(String title, String headText, String content) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle(title);
        alert.setHeaderText(headText);
        alert.setContentText(content);
        alert.getDialogPane().setStyle("fx-font-size: 14;");
        alert.showAndWait();
    }

    public static void showAlertLater(String title, String headText, String content){
        Platform.runLater(() -> showAlert(title, headText, content));
    }

    public static void showWarn(String title, String headText, String content) {
        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setTitle(title);
        alert.setHeaderText(headText);
        alert.setContentText(content);
        alert.showAndWait();
    }

    public static void showWarnLater(String title, String headText, String content){
        Platform.runLater(() -> showAlert(title, headText, content));
    }

    public static Optional<String> getInputDialog(String title, String headText, String content){
        TextInputDialog dialog = new TextInputDialog();
        dialog.setTitle(title);
        dialog.setHeaderText(headText);
        dialog.setContentText(content);
        dialog.getEditor().setPrefWidth(500);
        dialog.getEditor().setStyle("-fx-font-size: 14;");
        return dialog.showAndWait();
    }

}
